using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The ClassRoomLocationTableManager class is responsible for managing BO.ClassRoomLocationTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class ClassRoomLocationTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all ClassRoomLocationTable objects in the database.
/// </summary>
/// <returns>A list with all ClassRoomLocationTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static ClassRoomLocationTableList GetList(){
return ClassRoomLocationTableDB.GetList();
}

/// <summary>
/// Gets a single ClassRoomLocationTable from the database without its data.
/// </summary>
/// <param name="classRoomLocationKey">The ClassRoomLocationKey of the ClassRoomLocationTable in the database.</param>
/// <returns>A ClassRoomLocationTable object when the ClassRoomLocationKey exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static ClassRoomLocationTable GetItem(int classRoomLocationKey){
return GetItem(classRoomLocationKey, false);
}

/// <summary>
/// Gets a single ClassRoomLocationTable from the database.
/// </summary>
/// <param name="classRoomLocationKey">The ClassRoomLocationKey of the ClassRoomLocationTable in the database.</param>
/// <param name="getClassRoomLocationTableRecords">Determines whether to load all associated ClassRoomLocationTable records as well.</param>
/// <returns>
/// A ClassRoomLocationTable object when the ClassRoomLocationKey exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static ClassRoomLocationTable GetItem(int classRoomLocationKey, bool getClassRoomLocationTableRecords){
ClassRoomLocationTable myClassRoomLocationTable = ClassRoomLocationTableDB.GetItem(classRoomLocationKey);
if (myClassRoomLocationTable != null && getClassRoomLocationTableRecords){
myClassRoomLocationTable.timeScheduleTables = TimeScheduleTableDB.GetListByClassRoomLocationKey(classRoomLocationKey);
}
return myClassRoomLocationTable;
}

/// <summary>
/// Saves a ClassRoomLocationTable in the database.
/// </summary>
/// <param name="myClassRoomLocationTable">The ClassRoomLocationTable instance to save.</param>
/// <returns>The new ClassRoomLocationKey if the ClassRoomLocationTable is new in the database or the existing ClassRoomLocationKey when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static int Save(ClassRoomLocationTable myClassRoomLocationTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
int classRoomLocationTableClassRoomLocationKey = ClassRoomLocationTableDB.Save(myClassRoomLocationTable);
foreach (TimeScheduleTable myTimeScheduleTable in myClassRoomLocationTable.timeScheduleTables){
myTimeScheduleTable.ClassRoomLocationKey = classRoomLocationTableClassRoomLocationKey;
TimeScheduleTableDB.Save(myTimeScheduleTable);
}

//  Assign the ClassRoomLocationTable its new (or existing ClassRoomLocationKey).
myClassRoomLocationTable.ClassRoomLocationKey = classRoomLocationTableClassRoomLocationKey;

myTransactionScope.Complete();

return classRoomLocationTableClassRoomLocationKey;
}
}

/// <summary>
/// Deletes a ClassRoomLocationTable from the database.
/// </summary>
/// <param name="myClassRoomLocationTable">The ClassRoomLocationTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(ClassRoomLocationTable myClassRoomLocationTable){
return ClassRoomLocationTableDB.Delete(myClassRoomLocationTable.ClassRoomLocationKey);
}

#endregion

}

}
